package com.softhis.rekrutacja.client.view;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.softhis.rekrutacja.client.presenter.UsersModulePresenter.UsersModuleViewInterface;
import com.softhis.rekrutacja.client.view.widgets.impl.MyGxtButton;
import com.softhis.rekrutacja.client.view.widgets.impl.MyGxtGrid;
import com.softhis.rekrutacja.client.view.widgets.interfaces.IButton;
import com.softhis.rekrutacja.client.view.widgets.interfaces.IGrid;

public class UsersModuleView extends LayoutContainer implements UsersModuleViewInterface{

	private MyGxtButton deleteButton = new MyGxtButton("Usuń");
	private MyGxtButton newButton = new MyGxtButton("Nowy");
	private MyGxtGrid usersGrid = null;
	private ContentPanel content = new ContentPanel();
	private UserFormView form = new UserFormView();
	
	
	public UsersModuleView(){
		
		this.content.setHeaderVisible(false);
		this.content.setAutoHeight(true);
		this.content.setAutoWidth(true);
		
		this.newButton.setWidth(125);
		this.deleteButton.setWidth(125);
		
		form.getToolBar().add(newButton);
		form.getToolBar().add(deleteButton);
		
		this.add(content);
		this.add(form);
	}

	public void buildWidget( ListStore<BeanModel> store ) {
		
		List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

		configs.add( new ColumnConfig( "login", "Login", 150 ) );
		configs.add( new ColumnConfig( "password", "Hasło", 150 ) );
		configs.add( new ColumnConfig( "lastName", "Nazwisko", 150 ) );
		configs.add( new ColumnConfig( "name", "Imię", 150 ) );
		configs.add( new ColumnConfig( "birthDate", "Data Urodzenia", 150 ) );

		ColumnModel cm = new ColumnModel( configs );

		usersGrid = new MyGxtGrid( store, cm );
		usersGrid.setBorders( true );
		usersGrid.setHeight(200);
		usersGrid.setAutoWidth( true );
		usersGrid.setStripeRows( true );	
		content.add( usersGrid );
	}
	
	public IGrid getGrid(){
		return usersGrid;
	}	
	public IButton getDeleteButton() {
		return deleteButton;
	}
	public IButton getNewButton() {
		return newButton;
	}
	public UserFormView getUserForm(){
		return this.form;
	}
}
